
var DT = function() {} 

DT.prototype.Util = {
		
	onDomReady: function(callback) {
		if(document.addEventListener) {
			document.addEventListener("DOMContentLoaded", callback, false);
		} else {
			if(window.attachEvent) {
	            window.attachEvent('onload', callback);
			} else {
				return setTimeout(arguments.callee, 0);
			}
		}
	}

}


DT.prototype.Ajax = {
		
		getCaller: function() {
			var connector = null;
			if(window.XMLHttpRequest) {
				// If the W3C-supported request object is available, use that
				connector = new XMLHttpRequest();
			} else if(window.ActiveXObject) {
				// otherwise, if the IE-proprietary object is available, use that
				connector = new ActiveXObject('Microsoft.XMLHTTP');
			}			
			return connector;			
		},
		
		
		load: function(request) {
			// Take the url from the request object literal input,
			// or use an empty string value if it doesn't exist
			var url = request.url || "";
			var callback = request.callback || function() {};
			var connector = this.getCaller();
			if(connector) {
				connector.onreadystatechange = function() {
					if(connector.readyState == 4) {
						if(connector.status == 200) {
							// ATTENTION: connector.responseXML on IE
							// will still appear as text type instead of XML
							var text = connector.responseText;
							var xml = DT.Ajax.stringToXML(connector.responseText);
							callback.call(connector, {
								text: text,
								xml: xml
							});
						}
					}
				}
				connector.open("GET", url, true);
				connector.send(null);
			}
		},
		
		save: function(request) {
			var url = request.url || "";
			var callback = request.callback || function() {};
			
			// The data variable is a string of URL-encoded name-value pairs to send to
			// the server in the following format:
			// "parameter1=value1&parameter2=value2&..."
			var data = request.data || "";
			
			var connector = this.getCaller();
			
			if(connector) {
				connector.onreadystatechange = function() {
					if(connector.readyState == 4) {
						if(connector.status == 200) {
							// ATTENTION: connector.responseXML on IE
							// will still appear as text type instead of XML
							var text = connector.responseText;
							var xml = DT.Ajax.stringToXML(connector.responseText);
							callback.call(connector, {
								text: text,
								xml: xml
							});
						}
					}
				}
				connector.open("POST", url, true);
				connector.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				connector.setRequestHeader("Content-length", data.length);
				connector.setRequestHeader("Connection", "close");
				connector.send(data);
			}
		},
		
		
		stringToXML: function(XMLString) {
			var xmlDoc;
			if(window.ActiveXObject) {
				xmlDoc= new ActiveXObject("MSXML2.FreeThreadedDomDocument");
				xmlDoc.async=false;
				xmlDoc.loadXML(XMLString);
			} else if(window.DOMParser) {
				var xmlParser = new DOMParser();
				xmlDoc = xmlParser.parseFromString(XMLString, "text/xml");
			}
			return xmlDoc;
		}
		
		
}


DT.prototype.Xslt = {
		
		transform: function(xmlpath, xslpath, elementId, paramNames, paramValues) {
			var t_xmldoc;
			var t_xsldoc;		

			DT.Ajax.load({
				url: xmlpath,
				callback: function(response) {
					t_xmldoc = response.xml;
			
					DT.Ajax.load({
						url: xslpath,
						callback: function(response) {
							t_xsldoc = response.xml;
							XSLTTransform(t_xsldoc, t_xmldoc, elementId, paramNames, paramValues);
						}
					});
					
				}
			});
		
		},
		
		
		XSLTTransform: function(XSLStyleSheet, XMLData, InsertElementID, paramNames, paramValues) {
			document.getElementById(InsertElementID).innerHTML="";
			// alert("Enter XSLTTransform...");
			//Function to perform the XSLT based transformation
			if (window.ActiveXObject)
			{
				//Code for internet explorer
				var XSLTCompiled = new ActiveXObject("MSXML2.XSLTemplate");
				XSLTCompiled.stylesheet = XSLStyleSheet.documentElement;
				// create XSL-processor
				var XSLTProc = XSLTCompiled.createProcessor();
				XSLTProc.input = XMLData;
				
				if(typeof(paramNames)!='undefined' && paramNames.length>0 && paramNames.length==paramValues.length) {
					var i;
					for(i=0; i<paramNames.length; i++) {
						XSLTProc.addParameter(paramNames[i], paramValues[i]);
					}
				}
		
				XSLTProc.transform();
				document.getElementById(InsertElementID).innerHTML = XSLTProc.output;
				
			}
			else if (document.implementation && document.implementation.createDocument)
			{
				//Code for mozilla
				XSLTProc = new XSLTProcessor();
				XSLTProc.importStylesheet(XSLStyleSheet);
		
				if(typeof(paramNames)!='undefined' && paramNames.length>0 && paramNames.length==paramValues.length) {
					var i;
					for(i=0; i<paramNames.length; i++) {
						XSLTProc.setParameter(null, paramNames[i], paramValues[i]);
					}
				}
		
				TransformDoc = XSLTProc.transformToFragment(XMLData, document);
				document.getElementById(InsertElementID).appendChild(TransformDoc);
			}
			else
			{
				window.alert("Browser does not support XSLT.");
				return false;
			}
		}
		
}

DT = new DT();
